<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<html >
	 <head>
 		<title>${title }</title>
 		 <link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/main.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/searchBtn.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/searchCondition.css" />
	    <!-- js -->
 		<script language="JavaScript" src="${ctx}/static/scripts/check_all.js"></script>
 		<script language="JavaScript" src="${ctx}/static/scripts/set_select.js"></script>
 		<script language="JavaScript" src="${ctx}/static/scripts/waiting.js"></script>
 		<script language="JavaScript" src="${ctx}/static/scripts/crud.js"></script>
 		<script language="JavaScript" src="${ctx}/static/scripts/util.js"></script>
 		<script language="JavaScript" src="${ctx}/static/scripts/common.js"></script>
		<script language="javascript"src="${ctx}/static/scripts/WdatePicker/WdatePicker.js"></script>
	</head>
  <body onload="init()">
		<form action="${ctx}/orderBilling/list" method="post">
			<div class="width_100 group_box">
				<div class="group_search width_100">
				    <vvise:select id="custId" name="p_billingUnit" sqlname="getCust" ifSearch="true" displayText="用户单位" />
					<vvise:select id="status" name="p_status" sqlname="getCodeData" sqlparam="billing_status" displayText="状态" ifSearch="true"   />
					<vvise:searchInput id="buyUser" name="p_buyUser" displayText="申请人" />
					<vvise:searchInput id="startDate" name="p_startDate" defVal="${startDate}" 
			                endId="endtDate" endName="p_endtDate" endDefVal="${endDate}"
			                 type="time2" displayText="申请日期" dateFormat="yyyy-MM-dd"/>
               	 	<div class="clear_both"></div>
				</div>
				<vvise:funMenu menuId="${menuId}" />
			</div>
        </form>
        <div class="listFrame">
        	<iframe name="listFrame" id="listFrame" frameBorder="0"
				scrolling="auto" style="width: 100%;height:100%;"></iframe>
        </div>
	</body>
	<script language="javaScript">
  		var headers = {};
		headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
			//回车事件
		document.onkeydown = keyKistener;
		function keyKistener(e){
			e = e ? e:event;
			if(e.keyCode == 13){
				try{
					search();
				}catch(e){}
			}
		}
		function init(){
			set_iframe_h();
			$(window).resize(function(){
				set_iframe_h();
			});
			search();
			$('.easyui-combobox').combobox();
		}
		//设置ifream 高度
		function set_iframe_h(){
			var win_height  = $(window).height();
			var func_line_h = $('.group_box').outerHeight(true);
			var list_height = win_height - func_line_h;
			$('.listFrame').css('height',list_height-10);
		}
		function search(){
			waiting();
			document.forms[0].target = "listFrame";
			document.forms[0].submit();
		}
		
		/* 弹出详情页面 */
		function view(billingId,type){
			var pp = parent;
			if(type==1){
				doCreate("开票详情",pp.width3+100,480,"${ctx}/orderBilling/edit?billingId="+billingId);
			}else{
				doView("开票信息",pp.width3+100,480,"${ctx}/orderBilling/edit?billingId="+billingId+"&view=view");
			}
			
		}
		
		/* 弹出取票页面 */
		function openTackTickets(billingId,type){
			var pp = parent;
			if(type==1){
				doTackTickets("取票确认",pp.width1,400,"${ctx}/orderBilling/tackTicket?billingId="+billingId);
			}else{
				doView("取票信息",pp.width1,400,"${ctx}/orderBilling/tackTicket?billingId="+billingId+"&view=view");
			}
		}
		function doTackTickets(titleName,width,height,url){
			var pp = parent;
			pp.openWindow(titleName,width,height,url,[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					var pp = parent;
					var editFrame = pp.winFrame;
					var ticketWay = editFrame.$('#ticketWay').val();
					if(!pp.validData("ticketWay","请选择取票方式！"))
						return;
					
					var orderCode = editFrame.$('#orderCode').val();
					if(orderCode==2){
						if(!pp.validData("orderCode","请填写快递单号！"))
							return;
			    	}
					
					var ticketUser = editFrame.$('#ticketUser').val();
					if(!pp.validData("ticketUser","请填写取票人！"))
						return;
					
					var tickctDate = editFrame.$('#tickctDate').val();
					if(!pp.validData("tickctDate","请选择取票日期！"))
						return;
					
					var billingId = editFrame.$('#billingId').val();
					doSave("${ctx}/orderBilling/doTackTickets",billingId);
				}
			},{
				text:'取消',
				iconCls:'icon-no',
				handler:function(){
					pp.closeWindow();
				}
			}]);
		}
		
		/* 确认开票 */
		function save(){
			var pp = parent;
			var editFrame = pp.winFrame;
			var billingId = editFrame.$('#billingId').val();
			doSave("${ctx}/orderBilling/save",billingId);
		}
		
		/* 回款 */
		function showPayBack(billingId,type){
			var pp = parent;
			if(type==1){
				doPayBack("回款确认",pp.width3+100,480,"${ctx}/orderBilling/showPayBack?billingId="+billingId);
			}else{
				doView("回款详情信息",pp.width3+100,480,"${ctx}/orderBilling/showPayBack?billingId="+billingId+"&view=view");
			}				
		}
				
		function doPayBack(titleName,width,height,url){
			var pp = parent;
			pp.openWindow(titleName,width,height,url,[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					var pp = parent;
					var editFrame = pp.winFrame;
					var paymentWay = editFrame.$('#paymentWay').val();
					if(!pp.validData("paymentWay","请选择回款方式！"))
						return;
					
					var status = editFrame.$('#status').val();
					if(!pp.validData("status","请选择回款比例！"))
						return;
					
					var paymentAmount = editFrame.$('#paymentAmount').val();
					if(!pp.validData("paymentAmount","请填写回款金额！"))
						return;
					
					var paymentDate = editFrame.$('#paymentDate').val();
					if(!pp.validData("paymentDate","请选择回款日期！"))
						return;
					var totalPrice = editFrame.$('#totalPrice').val();
					var alreadyPaid = editFrame.$('#alreadyPaid').val();
					if(paymentAmount){
						var nowPrice = parseFloat(paymentAmount) + parseFloat(alreadyPaid);
						console.log(nowPrice);
						console.log(totalPrice);
						if(nowPrice>totalPrice){
							pp.alertMsg('回款总金额不能大于开票总金额！','warning',function(){
							});
							return;
						}else{
							if(status==4){ 
								console.log(1);//部分回款
								if(nowPrice>=totalPrice){
									console.log(2);
									pp.alertMsg('回款总金额等于开票总金额，请选择全部回款！','warning',function(){
									});
									return;
								}
							}else if(status==5){ //全部回款
								console.log(3);
								if(nowPrice<totalPrice){
									console.log(4);
									pp.alertMsg('该订单还没有全部回款，请选择部分回款！','warning',function(){
									});
									return;
								}
							}
						}
					}
					var billingId = editFrame.$('#billingId').val();
					console.log(111);
					doSave("${ctx}/orderBilling/doPayBack",billingId);
				}
			},{
				text:'取消',
				iconCls:'icon-no',
				handler:function(){
					pp.closeWindow();
				}
			}]);
		}
		/* 回款结束 */
		
		
		
		</script>
</html>